package com.example.summary.lianbiao;

import com.alibaba.fastjson.JSONObject;

/**
 * Created by wzn on 2019/3/26.
 */
public class LianBiaoFanZhuan {


    public static void main(String[] args) {
        LianBiaoNode node = new LianBiaoNode(1, new LianBiaoNode(2, new LianBiaoNode(3
                , new LianBiaoNode(4
                , new LianBiaoNode(5, new LianBiaoNode(6
                , new LianBiaoNode(7, new LianBiaoNode(8
                , new LianBiaoNode(9, new LianBiaoNode(10, null))))))))));
        LianBiaoNode head = new LianBiaoNode(-1, node);

        LianBiaoNode now = fanzhuan(head);

        while (null != now) {
            System.out.println(now.getI());
            now = now.getNext();
        }

    }

    private static LianBiaoNode fanzhuan( LianBiaoNode head) {
        LianBiaoNode lianBiaoNode = head.getNext();

        LianBiaoNode now = null;
        while (null != lianBiaoNode.getNext()) {
            now = lianBiaoNode.getNext();   // lianbiaoNode = 0,now=1
            lianBiaoNode.setNext(now.getNext()); //-1>0>>2>3>null  //now=1
            now.setNext(head.getNext()); //1>0>>2>3>null
            head.setNext(now);//-1>1>0>>2>3>null   //lianbiaoNode=0
        }

        return now;
    }
}
